{% extends 'base.html' %}
{% block content %}

<h1>{{ post.title }}</h1>

<ul>
{{post.body}}
<br>
<i>Posted by {{post.author}} on {{post.posted}}</i>
</ul>

{% if post.getComments %}
    <table border = 1>
    {% for comment in post.getComments %}
    <tr>
        <td width = 200>{{ comment.author }} <br> {{ comment.datePosted }}</td>
        <td width = 600>{{ comment.body }}
        {% if comment.editor %}
            <br><i>Edited by {{ comment.editor }} on {{comment.dateEdited }}</i>
        {% endif %}
        </td>
        <form action="" method="post">
            {% csrf_token %}
            {% if user.is_staff or user == comment.author %}
                <td><input type="submit" name="edit_comment" value="Edit" /></td>
            {% endif %}
            <input type="hidden" name="comment" value= {{ comment.id }} />
        </form> 
    </tr>
    {% endfor %}
    </table>
{% else %}
        <p><em>There are currently no comments on this post.</em></p>
{% endif %}



{% if user.is_authenticated %}

<H1> New Comment </H1>
<form action="" method="post">
{% csrf_token %}
{{ commentform.body}}
<br>
<input type="submit" value="Submit" />
</form>

{% else %}
<a href='/accounts/login/'>Login to Comment</a>
{% endif %}

{% endblock %}